package com.ourgame.tankgame.control;

import com.ourgame.tankgame.control.ai.AISystem;
import com.jme3.asset.AssetManager;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.input.InputManager;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.renderer.Camera;
import com.jme3.scene.control.AbstractControl;
import com.ourgame.tankgame.exception.TankGameNullPointException;

/**
 *控制系统 控制其它系统的工作
 * @author echoff
 */
public abstract class ControlSystem extends AbstractControl implements ActionListener, AnalogListener {

    public void onAction(String name, boolean isPressed, float tpf) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void onAnalog(String name, float value, float tpf) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }
    protected MoveSystem moveSystem;
    protected WeaponSystem weaponSystem;
    protected AISystem aiSystem;
    private InputManager inputManager;
    private Camera cam;
    private AssetManager assetManager;
    private PhysicsSpace space;

    /*
     * 构造方法
     */
    public ControlSystem() {
    }

    //********************************************************
    //*      get、set 区域                                    *
    //********************************************************
    

    public PhysicsSpace getPhysicsSpace() {
        if(null == space) {
            throw new TankGameNullPointException("physicsSpace", "WorldManagerState");
        }
        return space;
    }

    public void setPhysicsSpace(PhysicsSpace space) {
        this.space = space;
    }    
    
    public AssetManager getAssetManager() {
        if (null == assetManager) {
            throw new TankGameNullPointException("assetManager", "WorldManagerState");
        }
        return assetManager;
    }

    public void setAssetManager(AssetManager assetManager) {
        this.assetManager = assetManager;
    }

    public Camera getCam() {
        if (null == cam) {
            throw new TankGameNullPointException("cam", "WorldManagerState");
        }
        return cam;
    }

    public void setCam(Camera cam) {
        this.cam = cam;
    }

    public InputManager getInputManager() {
        if (null == inputManager) {
            throw new TankGameNullPointException("inputManager", "WorldManagerState");
        }
        return inputManager;
    }

    public void setInputManager(InputManager inputManager) {
        this.inputManager = inputManager;
    }

    public AISystem getAiSystem() {
        return aiSystem;
    }

    public void setAiSystem(AISystem aiSystem) {
        this.aiSystem = aiSystem;
    }

    public MoveSystem getMoveSystem() {
        return moveSystem;
    }

    public void setMoveSystem(MoveSystem moveSystem) {
        this.moveSystem = moveSystem;
    }

    public WeaponSystem getWeaponSystem() {
        return weaponSystem;
    }

    public void setWeaponSystem(WeaponSystem weaponSystem) {
        this.weaponSystem = weaponSystem;
    }

    /**
     * 初始化所有Control的工作。
     */
    public void init() {
        this.initControlSystem();
        moveSystem.initMoveSystem();
        weaponSystem.initWeaponSystem();
    }

    public abstract void initControlSystem();

    public void addWeaponSystem(WeaponSystem weaponSystem) {
        this.weaponSystem = weaponSystem;
        this.weaponSystem.setControler(this);
        spatial.addControl(weaponSystem);
    }

    public void addMoveSystem(MoveSystem moveSystem) {
        this.moveSystem = moveSystem;
        this.moveSystem.setControler(this);
        spatial.addControl(moveSystem);
    }
}
